package view;

import java.awt.Component;
import java.awt.Image;
import java.util.Locale;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

public class ExchangerComboBoxRenderer extends JLabel implements ListCellRenderer{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ResourceBundleWrapper resourceBundleWrapper;
	
	public ExchangerComboBoxRenderer() {
        setOpaque(true);
        setHorizontalAlignment(LEFT);
        setVerticalAlignment(CENTER);
    }
	
	public ExchangerComboBoxRenderer(ResourceBundleWrapper resourceBundleWrapper) {
        setOpaque(true);
        setHorizontalAlignment(LEFT);
        setVerticalAlignment(CENTER);
        this.resourceBundleWrapper = resourceBundleWrapper;
    }
    
    public Component getListCellRendererComponent(
                                       JList list,
                                       Object value,
                                       int index,
                                       boolean isSelected,
                                       boolean cellHasFocus) {
        if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
        } else {
            setBackground(list.getBackground());
            setForeground(list.getForeground());
        }

        if (value instanceof Locale){
            setText(((Locale)value).getDisplayLanguage(((Locale)value)));
            setFont(list.getFont());
        }
        if(value instanceof String[]){
        	ImageIcon img = new ImageIcon(((String[])value)[0]);
        	img.setImage(img.getImage().getScaledInstance(15, 13, Image.SCALE_DEFAULT));
        	setIcon(img);
        	setText(this.resourceBundleWrapper.getString(((String[])value)[2]));
        	setFont(list.getFont());
        }
        if(value == null){
        	setIcon(null);
        	setText("");
        }

        return this;
    }


}
